/*
 * urlhandler.h
 *
 *  Created on: 09/07/2009
 *      Author: andre
 */

#ifndef URLHANDLER_H_
#define URLHANDLER_H_

#include "requesthandler.h"

#define UNDEFINED -1
#define NOEVENT 0
#define STARTED 1
#define STOPPED 2
#define COMPLETED 3

#define INFO_HASH_SIZE 20
#define PEER_ID_SIZE 20
#define KEY_SIZE 20

//numero minimo de parametro pr request ser valido
#define MINIMAL_NUMBER_OF_PARAMETERS 6
#define EMPTY_ARRAY "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

#define REQUEST_OK 0
#define INFO_HASH_TOO_SMALL -2
#define PEER_ID_TOO_SMALL -3
#define TOO_FEW_PARAMETERS_IN_REQUEST -4
#define PORT_NUMBER_TOO_LOW -5
#define DOWNLOADED_IS_NEGATIVE -6
#define UPLOADED_IS_NEGATIVE -6
#define LEFT_IS_NEGATIVE -6
#define REQUEST_URL_IS_NULL -7
#define REQUEST_WITHOUT_INFO_HASH -8
#define REQUEST_WITHOUT_PEER_ID -9
#define REQUEST_WITHOUT_PORT -10
#define REQUEST_WITHOUT_DOWNLOADED -11
#define REQUEST_WITHOUT_UPLOADED -12
#define REQUEST_WITHOUT_LEFT -13
#define INVALID_CHAR_IN_URL_ENCODING -14

#define ONE_BITMASK 16
#define TWO_BITMASK 32
#define THREE_BITMASK 48
#define FOUR_BITMASK 64
#define FIVE_BITMASK 80
#define SIX_BITMASK 96
#define SEVEN_BITMASK 112
#define EIGHT_BITMASK 128
#define NINE_BITMASK 144
#define A_BITMASK 160
#define B_BITMASK 176
#define C_BITMASK 192
#define D_BITMASK 208
#define E_BITMASK 224
#define F_BITMASK 240

int decodeUrl(char* encodedUrl, char *decodedString, int encodedUrlLength);


int getAnnounceParameters(char* requestUrl, AnnounceParameters *trackerRequest);

inline int isAnnounce(char* requestUrl);

inline int isScrape(char* requestUrl);

#endif
/* URLHANDLER_H_ */
